<template>
  <BasicModal
    v-bind="$attrs"
    @register="registerModal"
    :title="t('common.formText')"
    width="800px"
    :footer="null"
  >
    <BasicForm @register="registerForm" @submit="handleSubmit" />
  </BasicModal>
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { BasicForm, useForm } from '/@/components/Form';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { getFormProps } from './fromData';
  import { patientApi } from '/@/api/console/patient';

  export default defineComponent({
    name: 'FormModal',
    components: { BasicModal, BasicForm },
    emits: ['create', 'register'],
    setup(_, { emit }) {
      const { t } = useI18n();
      const [registerForm] = useForm(getFormProps());
      const [registerModal, { closeModal }] = useModalInner();
      const handleSubmit = async (params: Recordable) => {
        emit('create', await patientApi.create(params));
        closeModal();
      };
      return {
        registerModal,
        registerForm,
        handleSubmit,
        t,
      };
    },
  });
</script>
<style lang="less" scoped></style>
